package com.allwees.bs.module.oms.account.runner;

import com.allwees.bs.module.oms.entity.AccountTransit;
import com.allwees.bs.module.oms.entity.OmsOrderItem;
import com.allwees.bs.module.oms.entity.OrderItem;
import com.allwees.bs.module.oms.service.AccountTransitService;
import com.allwees.core.common.util.MoneyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

@Component
public class AccountTransitUtils {

    @Autowired
    private AccountTransitService accountTransitService;


    public void accountTransit(OrderItem orderItem,String accountTransitAction) {
        AccountTransit accountTransit = new AccountTransit();
        accountTransit.setAccountTransitAction(accountTransitAction);
        accountTransit.setOrderNo(orderItem.getOrderNo());
        accountTransit.setOrderUuid(orderItem.getOrderUuid());
        accountTransit.setOrderItemUuid(orderItem.getUuid());
        accountTransit.setBranchUuid(orderItem.getRetailerUuid());
        BigDecimal skuAmount = MoneyUtil.mul(orderItem.getPrice(), BigDecimal.valueOf(orderItem.getQuantity()));
        BigDecimal skuShippingAmount = MoneyUtil.mul(orderItem.getShippingPrice(), BigDecimal.valueOf(orderItem.getQuantity()));
        accountTransit.setAmount(MoneyUtil.add(skuAmount,skuShippingAmount));
        accountTransit.setIsDo(0);
        //accountTransit.setCanShippingAt(orderItem.getCanShippingAt());
        accountTransit.setUserUuid(orderItem.getUserUuid());
        accountTransitService.save(accountTransit);
    }

    public void accountTransit(OmsOrderItem omsOrderItem, String accountTransitAction) {
        AccountTransit accountTransit = new AccountTransit();
        accountTransit.setAccountTransitAction(accountTransitAction);
        accountTransit.setOrderNo(omsOrderItem.getOrderNo());
        accountTransit.setOrderUuid(omsOrderItem.getOrderUuid());
        accountTransit.setOrderItemUuid(omsOrderItem.getUuid());
        accountTransit.setBranchUuid(omsOrderItem.getRetailerUuid());
        BigDecimal skuAmount = MoneyUtil.mul(omsOrderItem.getPrice(), BigDecimal.valueOf(omsOrderItem.getQuantity()));
        BigDecimal skuShippingAmount = MoneyUtil.mul(omsOrderItem.getShippingPrice(), BigDecimal.valueOf(omsOrderItem.getQuantity()));
        accountTransit.setAmount(MoneyUtil.add(skuAmount,skuShippingAmount));
        accountTransit.setIsDo(0);
        //accountTransit.setCanShippingAt(omsOrderItem.getCanShippingAt());
        accountTransit.setUserUuid(omsOrderItem.getUserUuid());
        accountTransitService.save(accountTransit);
    }
}
